package com.thinkgem.jeesite.quartz;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.thinkgem.jeesite.common.emu.OnlineStatus;
import com.thinkgem.jeesite.modules.equipment.entity.EleEquipment;
import com.thinkgem.jeesite.modules.equipment.service.EleEquipmentService;

public class EquipmentOnlineStatusJob {
	@Autowired
	private EleEquipmentService eleEquipmentService;
	
	public void updateEquipmentOnlineStatus(){
		System.out.println("Equipment Online Status Update......................Start");
		EleEquipment cond1 = new EleEquipment();
		long current = System.currentTimeMillis();
		cond1.setDelFlag(EleEquipment.DEL_FLAG_NORMAL);
		cond1.setState(OnlineStatus.Online.getIndex());
		List<EleEquipment> equipmentList = eleEquipmentService.findList(cond1);
		
		EleEquipment cond2 = new EleEquipment();
		cond2.setDelFlag(EleEquipment.DEL_FLAG_NORMAL);
		cond2.setState(OnlineStatus.Publishing.getIndex());
		equipmentList.addAll(eleEquipmentService.findList(cond2));
		for(EleEquipment ee:equipmentList){
			if(current - ee.getStateDate().getTime() > 1*60*1000){
				eleEquipmentService.updateOnlineStatus(ee.getId(), OnlineStatus.Offline.getIndex());
			}
		}
		System.out.println("Equipment Online Status Update......................Start");

	}
}
